<?php
namespace Erp\C\Orders\Tn\Api;
use Erp\C\Orders\Tn\Api\ApiShippingModule;
use Fn;

class ApiYtModule extends ApiShippingModule{
	public $OrderService,$account,$ApiSecret,$ApiToken,$DeveloperToken,$Header,$url,$sellerId;
	/**
	 *认证初始化
	 *@param
	 */
	public function __construct(){
		$isSandbox = false;

		// $this->OrderService = $isSandbox? 'http://120.55.205.164/api/RmlParcels' : 'http://120.55.205.164/api/RmlParcels';
		$this->OrderService = $isSandbox? 'http://120.76.199.53:8034/LMS.API/api/WayBill/BatchAdd' : 'http://api.yunexpress.com/LMS.API/api/WayBill/BatchAdd';
		$this->url=$this->OrderService;
		$this->pdfUrl = $isSandbox? 'http://120.76.199.53:8035/Api/PrintUrl' : 'http://api.yunexpress.com/LMS.API.Lable/Api/PrintUrl';
		$this->getTn = $isSandbox? 'http://120.76.199.53:8034//LMS.API/api/WayBill/GetTrackNumber?orderId=' : 'http://api.yunexpress.com/LMS.API/api/WayBill/GetTrackNumber?orderId=';
		$this->account=$isSandbox?'C88888':'C82883';//shahe/zhengshi 账号
		$this->ApiSecret=$isSandbox?'JCJaDQ68amA=':'JMMYbfkSFPI=';
		$this->ApiToken = base64_encode($this->account.'&'.$this->ApiSecret);
		$this->Header = array(
			'Authorization:basic '.$this->ApiToken,
			"Content-Type:text/json; charset=utf-8"
		);
		$this->account2=$isSandbox?'C88888':'C44542';
		$this->ApiSecret2=$isSandbox?'JCJaDQ68amA=':'z0O7bi659BI=';
		$this->ApiToken2 = base64_encode($this->account2.'&'.$this->ApiSecret2);
		$this->Header2 = array(
			'Authorization:basic '.$this->ApiToken2,
			"Content-Type:text/json; charset=utf-8"
		);
	}

	/**
	 *查询订单的tn号
	 *@param array $xmlData xml格式的数据,  string 订单号 字符串形式 '111221'
	 */
	/*public  function findTnCreatePackage($data){
		// $url = 'http://120.55.205.164/api/RmlParcels?ordernumber='.$orderid;
		$orderid = $data['orders_id'];
		$shipping = $data['shipping'];
		$url = 'http://120.55.205.164/api/GetOrder?ProductType='.$shipping.'&ordernumber='.$orderid;
		$headers = $this->Header;
		$logFileName = 'kim_ooo';
		if($logFileName){
			Fn\App::log($logFileName,$jsonData,"云途 findTN Curl数据开始");
		}
		$res = $this->oneHttpRequest($url,'','GET',$headers);
		if($logFileName){
			Fn\App::log($logFileName,$res,"云途 findTN Curl数据结束");
		}
		$response[$orderid] = $res;
		return $response;
	}*/

	/**
	 *创建线上包裹
	 *@param array $jsonData array('orders_id'=>'json')
	 */
	public  function createAndConfirmPackages($jsonData){
		$logFileName = "ytApiGetMultiCurl".date("H",time());
		if($logFileName){
			Fn\App::log($logFileName,$jsonData,"云途请求TN Curl数据开始");
		}
		$multi_request_res=$this->multiCurl($jsonData);
		if($logFileName){
			Fn\App::log($logFileName,$multi_request_res,"云途请求TN Curl数据结束");
		}
		return $multi_request_res;
	}

	//api请求获取包裹标签pdf
	public  function createPackageLable($data,$headers){
		$url = $this->pdfUrl;
		// $headers = $this->Header;
		$response = $this->oneHttpRequest($url,$data,'POST',$headers);
		return $response;
	}

}

